package com.epoque.admin.server.config;

import com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect;
import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 
 * @ClassName: HystrixConfig
 * @Description: 熔断器配置类
 * @author qiuxianfeng
 * @date 2018年8月29日
 *
 */
@Configuration
public class HystrixConfig {

    /**
     * 
     * @Title: hystrixAspect
     * @author qiuxianfeng
     * @Description: 用来拦截处理HystrixCommand注解
     * @param @return    参数
     * @return HystrixCommandAspect    返回类型
     * @throws
     */
    @Bean
    public HystrixCommandAspect hystrixAspect() {
        return new HystrixCommandAspect();
    }

    /**
     * 
     * @Title: hystrixMetricsStreamServlet
     * @author qiuxianfeng
     * @Description: 用来像监控中心Dashboard发送stream信息
     * @param @return    参数
     * @return ServletRegistrationBean    返回类型
     * @throws
     */
    @Bean
    public ServletRegistrationBean hystrixMetricsStreamServlet() {
        ServletRegistrationBean registration = new ServletRegistrationBean(new HystrixMetricsStreamServlet());
        registration.addUrlMappings("/hystrix.stream");
        return registration;
    }

} 